package com.ruoyi.ucar.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.ucar.domain.TWithdrawRecord;
import com.ruoyi.ucar.domain.po.WithdrawRecordDetailQueryPo;
import com.ruoyi.ucar.domain.po.WithdrawRecordListQueryPo;
import com.ruoyi.ucar.moreq.WithdrawRecordDetailQueryMoReq;
import com.ruoyi.ucar.moreq.WithdrawRecordListQueryMoReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 提现记录Mapper接口
 * 
 * @author sungangbin
 * @date 2025-05-13
 */
@Mapper
public interface TWithdrawRecordMapper extends BaseMapper<TWithdrawRecord>
{
    /**
     * 查询提现记录
     * 
     * @param id 提现记录主键
     * @return 提现记录
     */
    public TWithdrawRecord selectTWithdrawRecordById(Long id);

    /**
     * 查询提现记录列表
     * 
     * @param tWithdrawRecord 提现记录
     * @return 提现记录集合
     */
    public List<TWithdrawRecord> selectTWithdrawRecordList(TWithdrawRecord tWithdrawRecord);

    /**
     * 新增提现记录
     * 
     * @param tWithdrawRecord 提现记录
     * @return 结果
     */
    public int insertTWithdrawRecord(TWithdrawRecord tWithdrawRecord);

    /**
     * 修改提现记录
     * 
     * @param tWithdrawRecord 提现记录
     * @return 结果
     */
    public int updateTWithdrawRecord(TWithdrawRecord tWithdrawRecord);

    /**
     * 删除提现记录
     * 
     * @param id 提现记录主键
     * @return 结果
     */
    public int deleteTWithdrawRecordById(Long id);

    /**
     * 批量删除提现记录
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTWithdrawRecordByIds(Long[] ids);

    @Select("<script>" +
            "   SELECT  " +
            "    w.id as id,  " +
            "    w.withdraw_record_uuid as withdrawRecordUuid,  " +
            "    w.withdraw_money as withdrawMoney,  " +
            "    w.now_balance as nowBalance,  " +
            "    w.old_balance as oldBalance,  " +
            "    w.withdraw_datetime as withdrawDatetime,  " +
            "    w.withdraw_way as withdrawWay,  " +
            "    w.withdraw_status as withdrawStatus,  " +
            "    w.withdraw_type as withdrawType,  " +
            "    c.customer_name as customerName,  " +
            "    c.customer_uuid as customerUuid,  " +
            "    c.customer_phone as customerPhone  " +
            "    FROM  " +
            "  t_withdraw_record w  " +
            "  LEFT JOIN t_customer c ON w.customer_uuid = c.customer_uuid"+
            "<where>" +
            "   <if test='queryParams.deleteFlag != null'>" +
            "       AND (w.delete_flag = #{queryParams.deleteFlag} " +
            "       AND c.delete_flag = #{queryParams.deleteFlag}) " +
            "   </if>" +
            "   <if test='queryParams.withdrawStatus != null and queryParams.withdrawStatus != \"\"'> AND w.withdraw_status = #{queryParams.withdrawStatus} </if>" +
            "   <if test='queryParams.withdrawType != null and queryParams.withdrawType != \"\"'> AND w.withdraw_type = #{queryParams.withdrawType} </if>" +
            "   <if test='queryParams.withdrawWay != null and queryParams.withdrawWay != \"\"'> AND w.withdraw_way = #{queryParams.withdrawWay} </if>" +
            "</where>" +
            " order by w.id desc "+
            "</script>")
    public IPage<WithdrawRecordListQueryPo> withdrawRecordListQueryPage(IPage<WithdrawRecordListQueryPo> page, @Param("queryParams") WithdrawRecordListQueryMoReq withdrawRecordListQueryMoReq);

    @Select("<script>" +
            "   SELECT  " +
            "    w.id as id,  " +
            "    w.withdraw_record_uuid as withdrawRecordUuid,  " +
            "    w.withdraw_money as withdrawMoney,  " +
            "    w.now_balance as nowBalance,  " +
            "    w.old_balance as oldBalance,  " +
            "    w.withdraw_datetime as withdrawDatetime,  " +
            "    w.withdraw_way as withdrawWay,  " +
            "    w.withdraw_status as withdrawStatus,  " +
            "    w.withdraw_type as withdrawType,  " +
            "    c.customer_name as customerName,  " +
            "    c.customer_uuid as customerUuid,  " +
            "    c.customer_phone as customerPhone  " +
            "    FROM  " +
            "  t_withdraw_record w  " +
            "  LEFT JOIN t_customer c ON w.customer_uuid = c.customer_uuid"+
            "<where>" +
            "   <if test='queryParams.deleteFlag != null'>" +
            "       AND (w.delete_flag = #{queryParams.deleteFlag} " +
            "       AND c.delete_flag = #{queryParams.deleteFlag}) " +
            "   </if>" +
            "   <if test='queryParams.id != null'> AND w.id = #{queryParams.id} </if>" +
            "   <if test='queryParams.withdrawRecordUuid != null and queryParams.withdrawRecordUuid != \"\"'> AND w.withdraw_record_uuid = #{queryParams.withdrawRecordUuid} </if>" +
            "</where>" +
            " order by w.id desc "+
            "</script>")
    public List<WithdrawRecordDetailQueryPo> withdrawRecordDetailQuery(@Param("queryParams") WithdrawRecordDetailQueryMoReq withdrawRecordDetailQueryMoReq);

}
